/*
图片选择器选后图片显示
包含图片和右上角删除按钮
*/
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:transparent_image/transparent_image.dart';
import 'dart:io';
class ImagePicked extends StatelessWidget {
  final String? imageUrl;
  final int? index;
  final ValueChanged<int?>? valueChanged;
  final String? path;
  ImagePicked({this.imageUrl, this.index, this.valueChanged,this.path});

  void _handleCancel() {
    valueChanged!(index);
  }

  @override
  Widget build(BuildContext context) {

    Image image;
    if(imageUrl!.startsWith("http")){

      image = Image.network(imageUrl!);
    } else {

      image = Image.asset('${path}${imageUrl}');
    }
    return new Stack(
      alignment: Alignment(0.92, -0.92),
      children: <Widget>[
        new FadeInImage(
          placeholder: new MemoryImage(kTransparentImage),
          //判断imageUrl是否包含uploadfile 返回true为工单详情返回的图片 false为新添加的图片  AssetImage方式ios显示 android不显示图片
          image: (imageUrl!.contains("uploadfile")?NetworkImage(imageUrl!):new FileImage(File('$path$imageUrl'))) as ImageProvider<Object>,//new AssetImage('${path}${imageUrl}'),
          fit: BoxFit.fill,
          width: (MediaQuery.of(context).size.width - 32.0 - 8.0) / 3,
          height: (MediaQuery.of(context).size.width - 32.0 - 8.0) / 3,
        ),
        new GestureDetector(
          onTap: _handleCancel,
          child: new Container(
            decoration: new BoxDecoration(
              color: Colors.black45,
              shape: BoxShape.circle,
            ),
            child: new Icon(
              Icons.close,
              color: Colors.white,
              size: 20.0,
            ),
          ),
        )
      ],
    );
  }
}
